package com.ecube.mqtt;

import com.ecube.mqtt.MqttUtils;
import com.ecube.mqtt.mysql.Query;
import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Queue;

public class PileChargeSend {
    //充电桩启动充电
    @Test
    public void start() throws InterruptedException {

        //非常变参数
        String env = "UAT";
        String gunNo = "1";
        String chgID = "1100932023011800";
        String vin = "Yh821214354323424";
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long t = date.getTime() - 5*60*1000;
        String starttime = dateFormat.format(t);
        String orderSn = Query.getOrderSN(env, chgID, starttime);
        String index = Query.getSnno(env, chgID);

        //启动充电
        Boolean sendStart = MqttUtils.sendStartPileChargeMQTT(env, orderSn, index, chgID, gunNo, dateFormat.format(date));
        Thread.sleep(5000);
        //bms报文
        Boolean sendBMS = MqttUtils.sendBMS(env, orderSn, index, chgID, vin, dateFormat.format(date));
        Thread.sleep(5000);
        //充电开始
        Boolean sendRealData = MqttUtils.sendPileStartMQTT(env, orderSn, index, chgID, dateFormat.format(date));
        if(sendStart && sendRealData){
            System.out.println("充电启动成功");
        }else {
            System.out.println("充电启动失败");
        }

    }

    //充电桩实时状态
    @Test
    public void state() throws InterruptedException {
        //常变参数
        String soc = "70";
        //非常变参数
        String env = "UAT";
        String gunNo = "1";
        String chgID = "1100932023011800";
        String vin = "Yh821214354323424";
        String index = Query.getSnno(env, chgID);

        //实时状态
        Boolean sendState = MqttUtils.sendPileStateMQTT(env, soc, index, chgID, vin, gunNo);

        if(sendState){
            System.out.println("实时状态更新成功");
        }else {
            System.out.println("实时状态更新失败");
        }

    }


    //充电桩结束充电
    @Test
    public void stop() throws InterruptedException {

        //非常变参数
        String env = "UAT";
        String gunNo = "1";
        String chgID = "1100932023011800";
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long t = date.getTime() - 5*60*1000;
        String starttime = dateFormat.format(t);
        String orderSn = Query.getOrderSN(env, chgID, starttime);
        String index = Query.getSnno(env, chgID);

        //结束充电
        Boolean sendStop = MqttUtils.sendStopPileChargeMQTT(env, orderSn, index, chgID, gunNo, dateFormat.format(date));
        Thread.sleep(5000);
        //充电事件-停止
        Boolean sendStopEvent = MqttUtils.sendStopPileEventChargeMQTT(env, orderSn, index, chgID, dateFormat.format(date));

        if(sendStop && sendStopEvent){
            System.out.println("充电结束成功");
        }else {
            System.out.println("充电结束失败");
        }

    }

    @Test
    public void getEventJson() throws InterruptedException {

        //非常变参数
        String env = "UAT";
        String gunNo = "1";
        String chgID = "1100932023011800";
        String vin = "Yh821214354323424";
        String rateModelID = "65";
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long t = date.getTime() - 5*60*1000;
        String starttime = dateFormat.format(t);
        String orderSn = Query.getOrderSN(env, chgID, starttime);
        String index = Query.getSnno(env, chgID);

        //获取充电事件json
        MqttUtils.getEventJson(env, orderSn, index, chgID, vin, gunNo, rateModelID);


    }

//    @Test
//    public void sendEvent() throws InterruptedException {
//
//        //非常变参数
//        String env = "UAT";
//        String gunNo = "1";
//        String chgID = "1100932023011800";
//        String vin = "Yh821214354323424";
//        String rateModelID = "65";
//        String orderSn = Query.getOrderSN(env, chgID);
//        String index = Query.getSnno(env, chgID);
//
//        //获取充电事件json
//        //MqttUtils.getEventJson(env, orderSn, index, chgID, vin, gunNo, rateModelID);
//
//        //发送充电事件
//        Boolean sendEvent = MqttUtils.sendPileEventMQTT(env, orderSn, index, chgID, vin, gunNo, rateModelID);
//        if(sendEvent){
//            System.out.println("充电事件发送成功");
//        }else {
//            System.out.println("充电事件发送失败");
//        }
//
//    }
}
